<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>计时器</title>
		<script>
			function add0(n) {
				if (n < 10) {
					return "0" + n;
				} else {
					return n;
				}
			}
			var a = 0;
			var b = 0;
			var c = 0;
			function gettimer(){
			var timer = setInterval(function() {
				c++;
				if (c == 99) {
					b = b + 1;
					c = 0;
				}

				if (b == 99) {
					a = a + 1;
					b = 0;
				}

				document.querySelector("#sp").innerHTML = add0(a) + ":" + add0(b) + ":" + add0(c);
			}, 10);
			return timer;
			}
			var timer=gettimer();
			function go(t) {
		
				clearInterval(timer);
				if (t.value == "暂停") {
					clearInterval(timer);
					t.value = "启动";
				}else{
					 timer=gettimer();
					t.value="暂停";
				}
			}
			function overend(t){
				if(t.value=="结束"){
					clearInterval(timer);
					t.value="开始";
				}else{
					a=0;
					b=0;
					c=0;
					timer=gettimer();
					t.value="结束";
				}
			}
		</script>
	</head>
	<body>
		<div>
			<span id="sp"></span>
		</div>
		<div><input type="button" value="暂停" onclick="go(this)" /><input type="button" value="结束" onclick="overend(this)" />
		</div>
	</body>
</html>
